package com.jvtd.eyl.widget.adapter;

import android.support.annotation.Nullable;

import com.chad.library.adapter.base.BaseViewHolder;
import com.chad.library.adapter.base.MultipleItemRvAdapter;
import com.jvtd.eyl.bean.ui.HomeBean;
import com.jvtd.eyl.widget.provider.ClassProvider;
import com.jvtd.eyl.widget.provider.PeriodicalProvider;
import com.jvtd.eyl.widget.provider.TitleProvider;

import java.util.ArrayList;
import java.util.List;

/**
 * 精选列表条目
 *
 * 作者:chenlei
 * 时间:2018/11/12 4:43 PM
 */
public class HomeAdapter extends MultipleItemRvAdapter<HomeBean,BaseViewHolder> {
    public static final int ADAPTER_TYPE_CLASS = 1;//分类
    public static final int ADAPTER_TYPE_TITLE = 2;//全部期刊/标题
    public static final int ADAPTER_TYPE_PERIODICAL = 3;//期刊

    public HomeAdapter() {
        this(new ArrayList<>());
    }

    public HomeAdapter(@Nullable List<HomeBean> data) {
        super(data);
        finishInitialize();
    }

    @Override
    protected int getViewType(HomeBean homeBean) {
        int type = homeBean.getType();
        if (type == HomeBean.TYPE_TITLE)
            return ADAPTER_TYPE_TITLE;
        else if (type == HomeBean.TYPE_PERIODICAL)
            return ADAPTER_TYPE_PERIODICAL;
        else if (type == HomeBean.TYPE_CLASS)
            return ADAPTER_TYPE_CLASS;
        return 0;
    }

    @Override
    public void registerItemProvider() {
        mProviderDelegate.registerProvider(new ClassProvider());
        mProviderDelegate.registerProvider(new TitleProvider());
        mProviderDelegate.registerProvider(new PeriodicalProvider());
    }
}
